
#include <BRender>
#include <BSurface>
#include "member_BSurface.h"

using namespace BWE;

#define member					(*(member_BSurface*)_ptr)
#define member_allocate()		_ptr = new member_BSurface(this)
#define member_release()		delete (member_BSurface*)_ptr

BSurface::BSurface(const BString& name) : BGeometry(name)
{
	member_allocate();
}
BSurface::BSurface(int width, int height, int segx, int segy)
{
	member_allocate();
	this->setOrigin(BVector(-width * 0.5f, -height * 0.5f, 0.0f));
	this->setRight(BVector(width, 0.0f, 0.0f));
	this->setFront(BVector(0.0f, height, 0.0f));
	this->setRightSegment(segx);
	this->setFrontSegment(segy);
	this->flush();
}
BSurface::~BSurface()
{
	member_release();
}

void BSurface::setOrigin(const BVector& origin)
{
	if (member.origin != origin)
	{
		member.origin = origin;
		this->dirty();
	}
}
const BVector& BSurface::origin() const
{
	return member.origin;
}

void BSurface::setRight(const BVector& right)
{
	if (member.right != right)
	{
		member.right = right;
		this->dirty();
	}
}
const BVector& BSurface::right() const
{
	return member.right;
}

void BSurface::setFront(const BVector& front)
{
	if (member.front != front)
	{
		member.front = front;
		this->dirty();
	}
}
const BVector& BSurface::front() const
{
	return member.front;
}

void BSurface::setRightSegment(int segment)
{
	if (member.rightSegment != segment)
	{
		member.rightSegment = segment;
		this->dirty();
	}
}
int BSurface::rightSegment() const
{
	return member.rightSegment;
}

void BSurface::setFrontSegment(int segment)
{
	if (member.frontSegment != segment)
	{
		member.frontSegment = segment;
		this->dirty();
	}
}
int BSurface::frontSegment() const
{
	return member.frontSegment;
}

BBox BSurface::refresh()
{
	member.rebuild();
	return BGeometry::refresh();
}
